var root_path = getRootPath_web();
// var today_weather = {
//     data : {
//         "temperature":'20',
//         "humidity":"64",
//         "info":"晴",
//         "wid":"00",
//         "direct":"东南风",
//         "power":"4级",
//         "aqi":"54"
//     },
// };
var today_weather = {
    "data" : {
        "temperature": "20",
        "info": '晴'
    }
};
function getWeather(){
    var apiUrl = root_path + "/getWeather.do";
    // var weather;
    $.ajax({
        url: apiUrl,
        type: "GET",
        cache: false,
        dataType: 'json',
        async: false,
        success: function (result) {
            today_weather = result;
        },
        error: function () {
            console.log("Connect Failed");
        }
    });
}
// setTimeout(getWeather(), 1000*60*60*24)
// getWeather();

config1 = {
    //参数的说明
    interval: 1, //间隔天数，间隔为整数
    runNow: false, //是否⽴即运⾏
    time: "6:00:00" //执⾏的时间点 时在0~23之间}
}
config2 = {
    //参数的说明
    interval: 1, //间隔天数，间隔为整数
    runNow: false, //是否⽴即运⾏
    time: "16:00:00" //执⾏的时间点 时在0~23之间}
}

function timeoutFunc (config, getWeather){
    config.runNow && getWeather()
    const nowTime = new Date().getTime()
    const timePoints = config.time.split(':').map(i => parseInt(i))
    let recent = new Date().setHours(...timePoints)
    recent >= nowTime || (recent += 24 * 3600000)
    setTimeout(() => {
        getWeather()
        setInterval(getWeather(), config.interval * 3600000)
    }, recent - nowTime)

    console.log("timeoutFunc运行中")
}

timeoutFunc(config1, getWeather)
timeoutFunc(config2, getWeather)